package cn.iocoder.yudao.module.trade.controller.admin.deliverypickupstoreimage;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.trade.controller.admin.deliverypickupstoreimage.vo.*;
import cn.iocoder.yudao.module.trade.dal.dataobject.deliverypickupstoreimage.DeliveryPickUpStoreImageDO;
import cn.iocoder.yudao.module.trade.service.deliverypickupstoreimage.DeliveryPickUpStoreImageService;

@Tag(name = "管理后台 - 门店证件图片")
@RestController
@RequestMapping("/trade/delivery-pick-up-store-image")
@Validated
public class DeliveryPickUpStoreImageController {

    @Resource
    private DeliveryPickUpStoreImageService deliveryPickUpStoreImageService;

    @PostMapping("/create")
    @Operation(summary = "创建门店证件图片")
    @PreAuthorize("@ss.hasPermission('trade:delivery-pick-up-store-image:create')")
    public CommonResult<Integer> createDeliveryPickUpStoreImage(@Valid @RequestBody DeliveryPickUpStoreImageSaveReqVO createReqVO) {
        return success(deliveryPickUpStoreImageService.createDeliveryPickUpStoreImage(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新门店证件图片")
    @PreAuthorize("@ss.hasPermission('trade:delivery-pick-up-store-image:update')")
    public CommonResult<Boolean> updateDeliveryPickUpStoreImage(@Valid @RequestBody DeliveryPickUpStoreImageSaveReqVO updateReqVO) {
        deliveryPickUpStoreImageService.updateDeliveryPickUpStoreImage(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除门店证件图片")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('trade:delivery-pick-up-store-image:delete')")
    public CommonResult<Boolean> deleteDeliveryPickUpStoreImage(@RequestParam("id") Integer id) {
        deliveryPickUpStoreImageService.deleteDeliveryPickUpStoreImage(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得门店证件图片")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('trade:delivery-pick-up-store-image:query')")
    public CommonResult<DeliveryPickUpStoreImageRespVO> getDeliveryPickUpStoreImage(@RequestParam("id") Integer id) {
        DeliveryPickUpStoreImageDO deliveryPickUpStoreImage = deliveryPickUpStoreImageService.getDeliveryPickUpStoreImage(id);
        return success(BeanUtils.toBean(deliveryPickUpStoreImage, DeliveryPickUpStoreImageRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得门店证件图片分页")
    @PreAuthorize("@ss.hasPermission('trade:delivery-pick-up-store-image:query')")
    public CommonResult<PageResult<DeliveryPickUpStoreImageRespVO>> getDeliveryPickUpStoreImagePage(@Valid DeliveryPickUpStoreImagePageReqVO pageReqVO) {
        PageResult<DeliveryPickUpStoreImageDO> pageResult = deliveryPickUpStoreImageService.getDeliveryPickUpStoreImagePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DeliveryPickUpStoreImageRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出门店证件图片 Excel")
    @PreAuthorize("@ss.hasPermission('trade:delivery-pick-up-store-image:export')")
    @OperateLog(type = EXPORT)
    public void exportDeliveryPickUpStoreImageExcel(@Valid DeliveryPickUpStoreImagePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DeliveryPickUpStoreImageDO> list = deliveryPickUpStoreImageService.getDeliveryPickUpStoreImagePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "门店证件图片.xls", "数据", DeliveryPickUpStoreImageRespVO.class,
                        BeanUtils.toBean(list, DeliveryPickUpStoreImageRespVO.class));
    }

}